﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MeiTool.Common
{
    public static class ClassMethod
    {
        /// <summary>
        /// 将A类赋值到B类
        /// </summary>
        /// <typeparam name="TA"></typeparam>
        /// <typeparam name="TB"></typeparam>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public static void CopyAToB<TA, TB>(TA a, TB b)
        {
            var ParentType = typeof(TA);
            var Properties = ParentType.GetProperties();
            foreach (var Propertie in Properties)
            {
                //循环遍历属性
                if (Propertie.CanRead && Propertie.CanWrite)
                {
                    //进行属性拷贝
                    Propertie.SetValue(b, Propertie.GetValue(a, null), null);
                }
            }
        }
    }
}
